package com.netafull.analyze;

import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

public class AnalyzeXMLForHomepage {
	public List<News> getRss(String path) throws Exception {
		List<News> data = new ArrayList<News>();
		URL url = null;
		url = new URL(path);
		URLConnection myurlcon = url.openConnection();
		myurlcon.setConnectTimeout(15000);
		myurlcon.setReadTimeout(15000);
		myurlcon.connect();

		SAXParserFactory spf = SAXParserFactory.newInstance();
		SAXParser sp = spf.newSAXParser();
		XMLReader xr = sp.getXMLReader();
		AnalyzeXMLHandlerForHomepage myExampleHandler = new AnalyzeXMLHandlerForHomepage();
		xr.setContentHandler(myExampleHandler);
		xr.parse(new InputSource(url.openStream()));
		data = myExampleHandler.getParsedData();

		return data;

	}
}
